home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_msql.idb / usr / freeware / msql / tests / rtest.z / rtest
Text File  |  1998-10-27  |  3KB  |  128 lines

  1. #!/bin/sh
  2. # Regression tester for mSQL.
  3. #
  4. # This script just drives the individual tests in the rtest.src
  5. # directory.  Run it as "rtest <db>" where db is the name of a database.
  6. # The database will be created and destroyed during the testing so don't
  7. # use anything that already exists (the scripts wont let you anyway).
  8. #
  9. #                        bambi.
  10.  
  11. # If you want to do the testing on a machine other than the local box
  12. # (or you want to force a TCP connection) set the variable below to the
  13. # hostname of the box running the server
  14. #
  15. #MSQLHOST="-h fawn"
  16.  
  17.  
  18. #
  19. # Use a fresh DB ?
  20. FRESH=Y
  21.  
  22. # Do not uncomment this variable.  It is used to reset the test results
  23. # after a major change to the test suite or output format of msql
  24. #RESET=1
  25.  
  26. DB=$1
  27.  
  28. if test "$DB." = "."
  29. then
  30.     echo
  31.     echo "Bad usage.  Read the intro to the script for details!"
  32.     echo
  33.     exit 1
  34. fi
  35.  
  36. #
  37. # Where are the programs we need
  38. #
  39. MSQL_HOME=/usr/freeware/msql
  40. MSQLADMIN="$MSQL_HOME/bin/msqladmin"
  41. MSQL="$MSQL_HOME/bin/msql $MSQLHOST"
  42.  
  43. #MSQLADMIN="/usr/local/Hughes/bin/msqladmin"
  44. #MSQL="/usr/local/Hughes/bin/msql $MSQLHOST"
  45.  
  46. #
  47. # How can we echo without a newline?
  48. #
  49. if echo '\c' | grep -s c >/dev/null 2>&1
  50. then
  51.         ECHO_N="echo -n"
  52.         ECHO_C=""
  53. else
  54.         ECHO_N="echo"
  55.         ECHO_C='\c'
  56. fi
  57.  
  58. #
  59. # Find out the names of the tests
  60. #
  61. cd rtest.src
  62. TESTS=`ls [0-9]*.test | sort -n | sed "s/\.test\$//"`
  63. rm -f *.res
  64. COUNT=0
  65.  
  66. #
  67. # Setup a clean database
  68. #
  69. if test ".$FRESH" = ".Y"
  70. then
  71.     $MSQLADMIN -q drop $DB > /dev/null
  72.     $MSQLADMIN create $DB
  73.     if test $? -ne 0
  74.     then
  75.         echo
  76.         echo
  77.         echo "Couldn't setup new database for testing."
  78.         echo
  79.         exit 1
  80.     fi
  81. fi
  82.  
  83. #
  84. # Run through the tests and bail out if there's an error.
  85. #
  86. total_q=0
  87. echo
  88. if test "$RESET." = "."
  89. then
  90.     echo "Starting tests."
  91. else
  92.     echo "Starting tests in reset mode"
  93. fi
  94. for I in $TESTS
  95. do
  96.     $ECHO_N "Running test $I.$ECHO_C"
  97.     if test "$RESET." = "."
  98.     then
  99.         $MSQL $MSQHOST $DB < $I.test > $I.res 2>&1
  100.         diff $I.out $I.res > /dev/null
  101.         if test $? -ne 0 
  102.         then
  103.             echo "  FAILED !!!"
  104.             echo
  105.             echo
  106.             echo "ERROR : Regression test failed on test \"$I\"."
  107.             echo "Test results have been saved in rtest.src/*.res"
  108.             echo
  109.             exit 1
  110.         fi
  111.         num_q=`grep "\\g" $I.test | wc -l`
  112.         echo "  Passed.  All $num_q queries ran correctly."
  113.         total_q=`expr $total_q + $num_q`
  114.     else
  115.         echo
  116.         $MSQL $MSQHOST $DB < $I.test > $I.out 2>&1
  117.     fi
  118.     COUNT=`expr $COUNT + 1`
  119. done
  120.  
  121. echo
  122. echo
  123. echo "All $COUNT tests have passed.  $total_q queries executed."
  124. echo "Results of the individual tests can be found in rtest.src/*.res"
  125. echo
  126. exit 0
  127.